package com.pig.live.common.core.domain;

import com.pig.live.common.enums.ResultCodeEnum;

import java.io.Serializable;

/**
 * 全局返回消息
 *
 * @author gaojx
 * @since 2020/8/16
 */
public class ResultBean<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 是否成功
     */
    private boolean success = false;

    /**
     * 响应状态码
     */
    private String code;

    /**
     * 响应消息
     */
    private String message;

    /**
     * 响应数据
     */
    private T data;

    public ResultBean() {
    }

    public ResultBean(boolean success){
        this.success = success;
    }

    public ResultBean(boolean success, String message){
        this.success = success;
        this.message = message;
    }

    public ResultBean(boolean success, String message, T data) {
        this.success = success;
        this.message = message;
        this.data = data;
    }

    public ResultBean(String code, String message) {
        this.code = code;
        this.message = message;
    }

    public ResultBean(ResultCodeEnum errorCode){
        this.code = errorCode.getCode();
        this.message = errorCode.getMessage();
    }


    public boolean isSuccess() {
        return success;
    }

    public ResultBean<T> setSuccess(boolean success) {
        this.success = success;
        return this;
    }

    public String getCode() {
        return code;
    }

    public ResultBean<T> setCode(String code) {
        this.code = code;
        return this;
    }

    public String getMessage() {
        return message;
    }

    public ResultBean<T> setMessage(String message) {
        this.message = message;
        return this;
    }

    public T getData() {
        return data;
    }

    public ResultBean<T> setData(T data) {
        this.data = data;
        return this;
    }
}
